<template>
  <div class="bg-white rounded-20px p-30px h-full">
    <div class="flex items-center justify-between">
      <div class="flex items-center gap-10px">
        <el-image class="w-13px h-23px" :src="require('@/assets/images/analysis/before.png')" fit="contain"></el-image>
        <div class="text-20px font-bold text-black">终端</div>
      </div>
      <div class="flex items-center gap-10px">
        <div class="flex items-center gap-5px" style="border-right: 1px solid #AAB0BB; padding-right: 10px;">
          <div
            v-for="(dateItem, dateiIndex) in dateList"
            :key="dateiIndex"
            class="tag"
            :class="currentTag === dateiIndex ? 'active' : ''"
            @click="currentTag = dateiIndex"
          >{{ dateItem }}
          </div>
        </div>
        <el-image class="w-15px h-14px" :src="require('@/assets/images/analysis/download.png')" fit="contain"></el-image>
      </div>
    </div>

    <div class="mt-20px">
      <el-table
        v-loading="loading"
        :data="cardList"
        :border="false"
        stripe
        height="390px"
      >
        <el-table-column label="终端名称" prop="customerName" align="center"></el-table-column>
        <el-table-column label="工厂数量" prop="entryCount" align="center"></el-table-column>
        <el-table-column label="在途数量" prop="transportingCount" align="center"></el-table-column>
        <el-table-column label="三方仓数量" prop="triEntryCount" align="center"></el-table-column>
        <el-table-column label="收货数量" prop="triOuCount" align="center"></el-table-column>
        <el-table-column label="总数量" align="center">
          <template slot-scope="scope">
            {{ (scope.row.entryCount || 0) + (scope.row.transportingCount || 0) + (scope.row.triEntryCount || 0) + (scope.row.triOuCount || 0) }}
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { warehouseCustomerStatusApi } from '@/api/hs/bigscreen';

export default {
  name: "TerminalData",
  data() {
    return {
      cardList: [],
      currentTag: 2,
      dateList: [
        '日',
        '周',
        '月'
      ],
      loading: false,
      interval: null,
    };
  },
  watch: {
    currentTag() {
      this.warehouseCustomerStatus();
    }
  },
  created() {
    this.warehouseCustomerStatus();
    this.interval = setInterval(() => {
      this.warehouseCustomerStatus();
    }, 10000);
  },
  methods: {
    warehouseCustomerStatus() {
      this.loading = true;
      return new Promise((resolve, reject) => {
        warehouseCustomerStatusApi(this.currentTag + 1)
        .then(res => {
          this.cardList = res.data || [];
          resolve(res.data);
        }).catch(err => {
          reject(err);
        })
        .finally(() => {
          this.loading = false;
        });
      });
    },
    clearDataInterval() {
      if (this.interval) {
        clearInterval(this.interval);
        this.interval = null;
      }
    },
  },
  destroyed() {
    this.clearDataInterval();
  }
};
</script>

<style lang="scss" scoped>
.line {
  height: 2px;
  background: linear-gradient(to right, #E8EFF8, #F5F8FC);
}
.tag {
  padding: 5px 10px;
  color: #AAB0BB;
  font-size: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  border-radius: 10px;
  &.active {
    color: #2386FF;
    border-color: #2386FF;
  }
}
:deep(.el-table) {
  box-shadow: none;
  border-radius: 0;
  &::before {
    height: 0;
  }
}
:deep(.el-table--striped .el-table__body tr.el-table__row--striped td.el-table__cell) {
  background-color: #F1F2F7;
}
:deep(.el-table td.el-table__cell) {
  border-bottom: none;
}
:deep(.el-table__body-wrapper) {
  &::-webkit-scrollbar-track-piece {
    background: rgb(211, 220, 230, 0.3);
  }

  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-thumb {
    background: rgb(153, 169, 191, 0.3);
    border-radius: 20px;
  }
}
</style>
